package com.magina.nety.config;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TestDemo implements Serializable {

    private String id;
    private String date;
    private String name;
    private String code;

    @Override
    public String toString( )  {
        return "TestDemo{" +
                "id='" + id + '\'' +
                ", date='" + date + '\'' +
                ", name='" + name + '\'' +
                ", code='" + code + '\'' +
                '}';
    }

    public static void main(String[] args) {
        String str = "{\"agentUserIds\":[],\"answerTime\":0,\"begin\":1557301105000,\"callNumList\":[],\"cutPoint\":30,\"end\":1565077105000,\"interval\":1,\"methodType\":\"search\",\"now\":false,\"orgId\":\"ketianyun\",\"sessionId\":\"18f374c0-50dc-47e2-98af-b2322dc4ab92\",\"type\":\"daily\",\"url\":\"/restapi/report/unReply/page\",\"waitType\":\"inqueue\"}";
        String md51 = "472cc914b21641c6da19983fbb589b32";
        String md52 = md5(str);
        System.out.println(md52);
    }
    //写一个md5加密的方法
    public static String md5(String plainText) {
        //定义一个字节数组
        byte[] secretBytes = null;
        try {
            // 生成一个MD5加密计算摘要
            MessageDigest md = MessageDigest.getInstance("MD5");
            //对字符串进行加密
            md.update(plainText.getBytes());
            //获得加密后的数据
            secretBytes = md.digest();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("没有md5这个算法！");
        }
        //将加密后的数据转换为16进制数字
        String md5code = new BigInteger(1, secretBytes).toString(16);// 16进制数字
        // 如果生成数字未满32位，需要前面补0
        for (int i = 0; i < 32 - md5code.length(); i++) {
            md5code = "0" + md5code;
        }
        return md5code;
    }

}
